package com.atguigu.base;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;
import java.util.TreeMap;

/**
 * @ClassName BaseController
 * @Description 此类描述:
 * @Author dangchen
 * @DateTime 2022-08-21 14:21
 * @Version 1.0
 */
public class BaseController {

    protected Map<String, Object> getFilters(HttpServletRequest request) {
        Enumeration<String> paramNames = request.getParameterNames();
        Map<String,Object> filters = new TreeMap<>();
        while (paramNames != null && paramNames.hasMoreElements()){
            String paramName = paramNames.nextElement();
            String[] values = request.getParameterValues(paramName);
            if (values != null && values.length != 0){
                if (values.length > 1){
                    filters.put(paramName,values);
                }else {
                    filters.put(paramName,values[0]);
                }
            }
        }
        if (!filters.containsKey("pageNum")) {
            filters.put("pageNum",1);
        }
        if (!filters.containsKey("pageSize")){
            filters.put("pageSize",5);
        }
        return filters;
    }
}
